home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip1292.zip / MKTONE.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  1KB  |  53 lines

  1. /*
  2. **  MKTONE.C
  3. **
  4. **  Original Copyright 1988-1991 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is functionally identical to the
  8. **  version originally published by the author in Tech Specialist
  9. **  magazine and is hereby donated to the public domain.
  10. */
  11.  
  12. #include "uclock.h"
  13. #include "sound.h"
  14.  
  15. static int usec_timeout(uclock_t start, uclock_t finish, uclock_t usecs)
  16. {
  17.       if (usecs >= (finish - start))
  18.             return 0;
  19.       else  return 1;
  20. }
  21.  
  22. void dosound(int freq)
  23. {
  24.       unsigned i;
  25.  
  26.       outp(C8253, SETIMER);
  27.       i = (unsigned)freq%256;
  28.       outp(F8253, i);
  29.       i = (unsigned)freq/256;
  30.       outp(F8253, i);
  31. }
  32.  
  33. void mktone(int freq, int update, unsigned delay)
  34. {
  35.       uclock_t start;
  36.  
  37.       if (0 == freq)
  38.       {
  39.             soundoff();
  40.             return;
  41.       }
  42.       dosound(freq);
  43.       if (update != UPDATE)
  44.             soundon();
  45.       if (delay == 0)
  46.             return;
  47.       start = usec_clock();
  48.       while (!usec_timeout(start, usec_clock(), 1000L * (long)delay))
  49.             ;
  50.       if (update == TOGGLE)
  51.             soundoff();
  52. }
  53.